package com.itheima.excel.model;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.itheima.pojo.Student;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
public class StudentModel {
    @ExcelProperty("姓名")
    private String name;
    
    @ExcelProperty("学号")
    private String no;
    
    @ExcelProperty("性别")
    private String genderStr;
    
    @ExcelProperty("手机号")
    private String phone;
    
    @ExcelProperty("身份证号")
    private String idCard;
    
    @ExcelProperty("是否来自院校")
    private String isCollegeStr;
    
    @ExcelProperty("居住地址")
    private String address;
    
    @ExcelProperty("学历")
    private String degreeStr;
    
    @ExcelProperty("毕业时间")
    private LocalDate graduationDate;

    @ExcelProperty("班级")
    private String clazzName;

    public Student toStudent(Integer clazzId){
        Student student = BeanUtil.copyProperties(this, Student.class);
        student.setGender("男".equals(this.getGenderStr()) ? 1 : 2);
        student.setIsCollege(("是").equals(this.getIsCollegeStr()) ? 1 : 0);
        switch (this.getDegreeStr()) {
            case "初中" -> student.setDegree(1);
            case "高中" -> student.setDegree(2);
            case "大专" -> student.setDegree(3);
            case "本科" -> student.setDegree(4);
            case "硕士" -> student.setDegree(5);
            case "博士" -> student.setDegree(6);
        }
        student.setClazzId(clazzId);
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(student.getCreateTime());
        return student;
    }

    public static StudentModel convert(Student student){
        StudentModel sm = BeanUtil.copyProperties(student, StudentModel.class);
        sm.setGenderStr(student.getGender() == 1 ? "男" : "女");
        sm.setIsCollegeStr(student.getIsCollege() == 1 ? "是" : "否");
        switch (student.getDegree()) {
            case 1 -> sm.setDegreeStr("初中");
            case 2 -> sm.setDegreeStr("高中");
            case 3 -> sm.setDegreeStr("大专");
            case 4 -> sm.setDegreeStr("本科");
            case 5 -> sm.setDegreeStr("硕士");
            case 6 -> sm.setDegreeStr("博士");
            default -> sm.setDegreeStr("未知");
        }
        return sm;
    }
}
